//
// Created by Administrator on 2022/1/26.
//

#ifndef CPP_LEARNING_LEETCODE347_H
#define CPP_LEARNING_LEETCODE347_H
#include <vector>
using namespace std;
#include <math.h>
#include <iostream>
#include <queue>
#include <functional>
#include <map>

using namespace std;

struct CompareQueueItem{
    bool operator()(std::pair<int, int>&a , std::pair< int, int>&b){
        return a.second < b.second;
    }
};


using QueueItem2 = std::pair<int, int>;
class Solution347 {
public:
    vector<int> topKFrequent(vector<int>& nums, int k) {
        map<int, int> maps;
        for(int i=0;i<nums.size();i++){
            maps[nums[i]] ++;
        }

        priority_queue<QueueItem2, vector<QueueItem2>, CompareQueueItem> maxQueue;
        for(auto& value : maps){
            maxQueue.push(value);
        }

        vector<int> result;
        for(int i=0;i<k;i++){
            result.push_back(maxQueue.top().first);
            maxQueue.pop();
        }
        return result;

    }
};

void test347(){
    Solution347 s;
    vector<int> nums = {1,2,2,3,4,5,5,5,6,6,6,6,7};
    s.topKFrequent(nums, 3);
}

#endif //CPP_LEARNING_LEETCODE977_H
